package com.metal.gear.common.util.tree;


import io.swagger.v3.oas.annotations.media.Schema;

import java.util.ArrayList;
import java.util.List;

@Schema(name = "树形结构节点实体",title = "树形结构节点实体")
public class SzlTreeNode<T,K> implements Comparable<SzlTreeNode<T,K>>{

    @Schema(name = "当前节点id")
    private T id;

    @Schema(name = "父节点id")
    private T parentId;

    @Schema(name = "节点顺序，越小优先级越高，默认0")
    private Comparable<?> weight = 0;

    @Schema(name = "子节点列表")
    private List<SzlTreeNode<T,K>> childrenList = new ArrayList<>();


    @Override
    public int compareTo(SzlTreeNode<T,K> otherNode) {
        final Comparable weight = this.getWeight();
        if (null != weight) {
            final Comparable weightOther = otherNode.getWeight();
            return weight.compareTo(weightOther);
        }
        return 0;
    }

    public T getId() {
        return id;
    }

    public void setId(T id) {
        this.id = id;
    }

    public T getParentId() {
        return parentId;
    }

    public void setParentId(T parentId) {
        this.parentId = parentId;
    }

    public Comparable<?> getWeight() {
        return weight;
    }

    public void setWeight(Comparable<?> weight) {
        this.weight = weight;
    }

    public List<SzlTreeNode<T,K>> getChildrenList() {
        return childrenList;
    }

    public void setChildrenList(List<SzlTreeNode<T,K>> childrenList) {
        this.childrenList = childrenList;
    }
}
